package com.ruoyi.web.controller.system;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.page.PageQuery;
import com.ruoyi.common.core.page.PageUtil;
import com.ruoyi.common.core.page.ResultEntity;
import com.ruoyi.system.domain.SysMaintain;
import com.ruoyi.system.domain.TDeviceMaintain;
import com.ruoyi.system.service.ITDeviceMaintainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

@Api(tags = "(客户端) 设备维护-维护记录")
@RestController
@RequestMapping("/client/device/maintain")
public class TDeviceMaintainController {
    @Autowired
    private ITDeviceMaintainService maintainService;

    @GetMapping("/list")
    @ApiOperation(value = "维护记录列表查询",response = TDeviceMaintain.class)
    public ResultEntity list(TDeviceMaintain params, PageQuery pageQuery){
        PageUtil.startPage(pageQuery);
        return ResultEntity.createSuccess(PageUtil.getPageList(maintainService.list(new LambdaQueryWrapper<TDeviceMaintain>()
                .eq(Objects.nonNull(params.getStatus()),TDeviceMaintain::getStatus,params.getStatus())
                .orderByDesc(TDeviceMaintain::getMaintainTime))));
    }

    @PostMapping("/{id}")
    @ApiOperation(value = "已维护标记")
    public ResultEntity approve(@PathVariable Long id) {
        TDeviceMaintain entity = new TDeviceMaintain();
        entity.setId(id);
        entity.setStatus(1);
        maintainService.updateById(entity);
        return ResultEntity.createSuccess();
    }
}
